
public class Queue {
	private int arraySize, bufferSize, start, insert;
	private boolean isFull, isEmpty;
	private byte[][] agentArray;
	
	/* constructor */
	public Queue(int a, int b){
		arraySize = a;
		bufferSize = b;
		start = 0;
		insert = 0;
		isFull = false;
		isEmpty = true;
		agentArray = new byte[arraySize+1][bufferSize];
	}
	
	/* while queue is not full
	 * add agent and update the insert pointer 
	 * if it becomes full update isFull
	 * after agent is added queue can not be empty so update isEmpty */
	public void enqueue(byte[] agentStream) throws FullException{
		if(isFull)
			throw new FullException("Agent Array Full");			

		agentArray[insert] = agentStream;
		insert++;
		
		isEmpty = false;
		if(start == insert+1 || (start == 0 && insert == arraySize+1))
				isFull = true;
	}
	
	/* while queue is not empty
	 * return agent and update the start pointer
	 * if it becomes empty update isEmpty
	 * after agent is removed queue can not be full so update isFull */
	public byte[] dequeue() throws EmptyException{
		if(isEmpty)
			throw new EmptyException("Agent Array Empty");

		start++;
		
		isFull = false;
		if(start == insert)
			isEmpty = true;
		
		return agentArray[start-1];
	}	
	
	public void reset(){
		isFull = false;
		isEmpty = true;
		start = insert;
	}
}